<template>
  <div class="app-container profile-container">
    <!-- 个人信息卡片 - 上部分 -->
    <el-card class="profile-card">
      <div class="profile-header">
        <div class="avatar-container">
          <img :src="userInfo.avatar" class="user-avatar" alt="用户头像">
          <div class="avatar-edit">
            <el-button size="mini" icon="el-icon-camera" circle @click="handleAvatarChange"></el-button>
          </div>
        </div>
        <h2 class="user-name">{{ userInfo.name }}</h2>
        <p class="user-title">{{ userInfo.title }}</p>
        <div class="user-tags">
          <el-tag v-for="tag in userInfo.tags" :key="tag" size="small" class="user-tag">{{ tag }}</el-tag>
        </div>
      </div>
      
      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
          <div class="profile-info">
            <div class="info-item" v-for="(item, index) in basicInfo" :key="index">
              <i :class="item.icon"></i>
              <span class="info-label">{{ item.label }}:</span>
              <span class="info-value">{{ item.value }}</span>
            </div>
          </div>
        </el-col>
        
        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
          <div class="profile-skills">
            <h4>专业技能</h4>
            <div class="skill-tags">
              <el-tag v-for="skill in userInfo.skills" :key="skill" type="success" size="small" class="skill-tag">{{ skill }}</el-tag>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-card>
    
    <!-- 毕业论文信息卡片 - 中部分 -->
    <el-card class="thesis-card mt-20">
      <div slot="header" class="card-header">
        <span><i class="el-icon-document"></i> 毕业论文信息</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="handleEditThesis">编辑</el-button>
      </div>
      
      <div class="thesis-content">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="thesis-item">
              <h4>论文题目</h4>
              <p class="thesis-title">{{ thesisInfo.title }}</p>
            </div>
            
            <div class="thesis-item">
              <h4>研究方向</h4>
              <p>{{ thesisInfo.direction }}</p>
            </div>
            
            <div class="thesis-item">
              <h4>指导教师</h4>
              <p>{{ thesisInfo.advisor }}</p>
            </div>
          </el-col>
          
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="thesis-item">
              <h4>论文摘要</h4>
              <p class="thesis-abstract">{{ thesisInfo.abstract }}</p>
            </div>
            
            <div class="thesis-item">
              <h4>关键词</h4>
              <div class="keyword-tags">
                <el-tag v-for="keyword in thesisInfo.keywords" :key="keyword" type="info" size="small" class="keyword-tag">{{ keyword }}</el-tag>
              </div>
            </div>
            
            <div class="thesis-item">
              <h4>完成时间</h4>
              <p>{{ thesisInfo.completionDate }}</p>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-card>
    
    <!-- 论文成果介绍卡片 - 下部分 -->
    <el-card class="achievement-card mt-20">
      <div slot="header" class="card-header">
        <span><i class="el-icon-trophy"></i> 论文成果介绍</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="handleEditAchievement">编辑</el-button>
      </div>
      
      <el-tabs v-model="activeTab" type="card">
        <el-tab-pane label="研究成果" name="research">
          <div class="achievement-content">
            <div v-for="(item, index) in achievementInfo.research" :key="index" class="achievement-item">
              <h4>{{ item.title }}</h4>
              <p>{{ item.description }}</p>
              <div class="achievement-meta">
                <span><i class="el-icon-date"></i> {{ item.date }}</span>
                <span v-if="item.link" class="ml-20">
                  <el-link type="primary" :href="item.link" target="_blank">
                    <i class="el-icon-link"></i> 查看详情
                  </el-link>
                </span>
              </div>
            </div>
          </div>
        </el-tab-pane>
        
        <el-tab-pane label="发表论文" name="papers">
          <div class="achievement-content">
            <el-timeline>
              <el-timeline-item v-for="(paper, index) in achievementInfo.papers" :key="index" :timestamp="paper.date" placement="top">
                <el-card>
                  <h4>{{ paper.title }}</h4>
                  <p>{{ paper.journal }}</p>
                  <p class="paper-authors">作者: {{ paper.authors }}</p>
                  <div class="paper-actions">
                    <el-button size="mini" type="primary" icon="el-icon-view" @click="viewPaper(paper)">查看</el-button>
                    <el-button size="mini" type="success" icon="el-icon-download" @click="downloadPaper(paper)">下载</el-button>
                  </div>
                </el-card>
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-tab-pane>
        
        <el-tab-pane label="获奖情况" name="awards">
          <div class="achievement-content">
            <div v-for="(award, index) in achievementInfo.awards" :key="index" class="award-item">
              <div class="award-icon">
                <i class="el-icon-medal"></i>
              </div>
              <div class="award-content">
                <h4>{{ award.name }}</h4>
                <p>{{ award.description }}</p>
                <p class="award-date">{{ award.date }}</p>
              </div>
            </div>
          </div>
        </el-tab-pane>
        
        <el-tab-pane label="项目经历" name="projects">
          <div class="achievement-content">
            <el-collapse v-model="activeProjects" accordion>
              <el-collapse-item v-for="(project, index) in achievementInfo.projects" :key="index" :title="project.name" :name="index">
                <div class="project-detail">
                  <p><strong>项目描述:</strong> {{ project.description }}</p>
                  <p><strong>担任角色:</strong> {{ project.role }}</p>
                  <p><strong>项目周期:</strong> {{ project.period }}</p>
                  <p><strong>技术栈:</strong></p>
                  <div class="tech-tags">
                    <el-tag v-for="tech in project.technologies" :key="tech" size="small" type="warning">{{ tech }}</el-tag>
                  </div>
                </div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Profile',
  data() {
    return {
      activeTab: 'research',
      activeProjects: ['0'],
      // 用户基本信息
      userInfo: {
        name: '杨晓琴',
        title: '22大数据1班学生',
        avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
        tags: ['应届毕业生', '数据分析', '前端开发'],
        skills: ['JavaScript', 'Vue.js', 'React', 'Node.js', 'Python', '数据结构与算法', '机器学习']
      },
      // 基本信息列表
      basicInfo: [
        { icon: 'el-icon-school', label: '学校', value: '仰恩大学' },
        { icon: 'el-icon-office-building', label: '学院', value: '工程技术学院' },
        { icon: 'el-icon-collection', label: '专业', value: '数据科学与大数据技术' },
        { icon: 'el-icon-user', label: '学号', value: '116420220010' },
        { icon: 'el-icon-message', label: '邮箱', value: '2034014220@qq.com' },
        { icon: 'el-icon-phone', label: '电话', value: '18030273040' }
      ],
      // 论文信息
      thesisInfo: {
        title: '基于深度学习的图像识别技术研究与应用',
        direction: '人工智能与计算机视觉',
        advisor: '张展老师',
        abstract: '本文主要研究了基于深度学习的图像识别技术，提出了一种改进的卷积神经网络模型，通过优化网络结构和训练策略，提高了图像识别的准确率和效率。实验结果表明，所提出的模型在多个公开数据集上均取得了优于现有方法的性能，为图像识别技术的实际应用提供了新的思路和方法。',
        keywords: ['深度学习', '图像识别', '卷积神经网络', '模型优化', '计算机视觉'],
        completionDate: '2023年6月'
      },
      // 成果信息
      achievementInfo: {
        research: [
          {
            title: '改进的卷积神经网络模型',
            description: '提出了一种新的卷积神经网络结构，通过引入注意力机制和残差连接，提高了图像识别的准确率。',
            date: '2023年3月',
            link: 'https://example.com/research1'
          },
          {
            title: '自适应学习率优化算法',
            description: '设计了一种自适应学习率调整算法，能够根据训练过程中的梯度变化动态调整学习率，加速模型收敛。',
            date: '2023年1月',
            link: 'https://example.com/research2'
          }
        ],
        papers: [
          {
            title: '基于深度学习的图像识别技术研究',
            journal: '计算机学报',
            authors: '杨晓琴, 李四, 王五',
            date: '2023-05-15'
          },
          {
            title: '自适应学习率在深度学习中的应用',
            journal: '软件学报',
            authors: '杨晓琴, 赵六',
            date: '2023-02-20'
          }
        ],
        awards: [
          {
            name: '优秀研究生奖学金',
            description: '因学习成绩优异和科研成果突出获得校级优秀研究生奖学金',
            date: '2022年12月'
          },
          {
            name: '学术创新大赛一等奖',
            description: '参加全国大学生学术创新大赛，凭借深度学习图像识别项目获得一等奖',
            date: '2022年10月'
          }
        ],
        projects: [
          {
            name: '智能图像识别系统',
            description: '开发了一套基于深度学习的智能图像识别系统，可用于多种场景下的图像分类和目标检测。',
            role: '项目负责人',
            period: '2022年3月 - 2022年12月',
            technologies: ['Python', 'TensorFlow', 'Flask', 'Docker', 'Vue.js']
          },
          {
            name: '学术论文管理系统',
            description: '设计并实现了一个学术论文管理系统，支持论文上传、分类、检索和统计分析等功能。',
            role: '前端开发工程师',
            period: '2021年9月 - 2022年2月',
            technologies: ['Vue.js', 'Element UI', 'Node.js', 'MongoDB']
          }
        ]
      }
    }
  },
  methods: {
    handleAvatarChange() {
      // 创建一个隐藏的文件输入元素
      const input = document.createElement('input')
      input.type = 'file'
      input.accept = 'image/*'
      
      input.onchange = (event) => {
        const file = event.target.files[0]
        if (file) {
          // 检查文件大小，限制为5MB
          if (file.size > 5 * 1024 * 1024) {
            this.$message.error('图片大小不能超过5MB')
            return
          }
          
          // 使用FileReader读取文件
          const reader = new FileReader()
          reader.onload = (e) => {
            // 更新头像URL
            this.userInfo.avatar = e.target.result
            this.$message.success('头像更新成功')
          }
          reader.readAsDataURL(file)
        }
      }
      
      // 触发文件选择对话框
      input.click()
    },
    handleEditThesis() {
      this.$message.info('论文信息编辑功能待实现')
    },
    handleEditAchievement() {
      this.$message.info('成果信息编辑功能待实现')
    },
    viewPaper(paper) {
      this.$message.success(`查看论文: ${paper.title}`)
    },
    downloadPaper(paper) {
      this.$message.success(`下载论文: ${paper.title}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.profile-container {
  padding: 20px;
  
  .profile-card, .thesis-card, .achievement-card {
    margin-bottom: 20px;
    
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      span {
        font-weight: bold;
        font-size: 16px;
        
        i {
          margin-right: 8px;
          color: #409EFF;
        }
      }
    }
  }
  
  .profile-header {
    text-align: center;
    
    .avatar-container {
      position: relative;
      display: inline-block;
      margin-bottom: 15px;
      
      .user-avatar {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        border: 4px solid #409EFF;
      }
      
      .avatar-edit {
        position: absolute;
        bottom: 5px;
        right: 5px;
        background: #409EFF;
        border-radius: 50%;
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        
        .el-button {
          padding: 0;
          border: none;
          background: transparent;
          color: white;
        }
      }
    }
    
    .user-name {
      margin: 10px 0;
      color: #303133;
    }
    
    .user-title {
      color: #606266;
      margin-bottom: 15px;
    }
    
    .user-tags {
      .user-tag {
        margin: 0 5px 5px 0;
      }
    }
  }
  
  .profile-info {
    .info-item {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      
      i {
        margin-right: 10px;
        color: #409EFF;
        width: 16px;
      }
      
      .info-label {
        font-weight: bold;
        margin-right: 10px;
        min-width: 60px;
      }
      
      .info-value {
        color: #606266;
      }
    }
  }
  
  .profile-skills {
    h4 {
      margin-bottom: 10px;
      color: #303133;
    }
    
    .skill-tags {
      .skill-tag {
        margin: 0 5px 5px 0;
      }
    }
  }
  
  .thesis-content {
    .thesis-item {
      margin-bottom: 20px;
      
      h4 {
        color: #303133;
        margin-bottom: 8px;
      }
      
      .thesis-title {
        font-size: 16px;
        font-weight: bold;
        color: #409EFF;
      }
      
      .thesis-abstract {
        line-height: 1.6;
        text-indent: 2em;
      }
      
      .keyword-tags {
        .keyword-tag {
          margin: 0 5px 5px 0;
        }
      }
    }
  }
  
  .achievement-content {
    .achievement-item {
      margin-bottom: 20px;
      padding-bottom: 15px;
      border-bottom: 1px solid #EBEEF5;
      
      &:last-child {
        border-bottom: none;
      }
      
      h4 {
        color: #303133;
        margin-bottom: 8px;
      }
      
      .achievement-meta {
        margin-top: 10px;
        color: #909399;
        font-size: 14px;
        
        .ml-20 {
          margin-left: 20px;
        }
      }
    }
    
    .paper-actions {
      margin-top: 10px;
    }
    
    .award-item {
      display: flex;
      margin-bottom: 20px;
      
      .award-icon {
        margin-right: 15px;
        
        i {
          font-size: 24px;
          color: #E6A23C;
        }
      }
      
      .award-content {
        flex: 1;
        
        h4 {
          color: #303133;
          margin-bottom: 5px;
        }
        
        .award-date {
          color: #909399;
          font-size: 14px;
          margin-top: 5px;
        }
      }
    }
    
    .project-detail {
      p {
        margin-bottom: 10px;
        
        strong {
          color: #303133;
        }
      }
      
      .tech-tags {
        .el-tag {
          margin-right: 5px;
          margin-bottom: 5px;
        }
      }
    }
  }
}

.mt-20 {
  margin-top: 20px;
}
</style>